
//查询已发送邮件
import Vue from "vue";

export const webList = (self, tiyData) => {
  self.$Spin.show();
  self.$ySpliceAll(tiyData.tData.emailList);

  let param = {
    "pageSize": tiyData.tPage.stepNumber,
    "pageNum": tiyData.tPage.currentPage,
    "type": tiyData.tParam.type,
    "startTime": tiyData.tParam.startTime,
    "endTime": tiyData.tParam.endTime,
  };

  if(tiyData.tParam.startTime){
    param.startTime = Vue.prototype.$tiyQueryTime(new Date(tiyData.tParam.startTime).getTime());
  }
  if(tiyData.tParam.endTime){
    param.endTime = Vue.prototype.$tiyQueryTime(new Date(tiyData.tParam.endTime).getTime());
  }

  self.$apiEmail.queryFailEmailList(param).then(function (response) {
    if(response.success){
      let emailPage = response.result;
      tiyData.tPage.total = emailPage.total;
      tiyData.tPage.stepNumber = emailPage.pageSize;
      emailPage.list.forEach(
        function (item) {
          tiyData.tData.emailList.push(item);
        }
      );
    }else{
      self.$Message.error(response.errorMessage);
    }
    self.$Spin.hide();
  });
};

/**
 * 处理邮件
 * @param self
 * @param tiyData
 */
export const dealFailEmail = (self, tiyData,id) => {
  let ids=[];
  ids.push(id);
  let param = {
    "ids": ids,
  };
  self.$apiEmail.dealFailEmail(param).then(function (response) {
    if(response.success){
      self.$Message.info("失败邮件处理成功！");
      self.search();
    }else{
      self.$Message.error(response.errorMessage);
    }
    self.$Spin.hide();
  });
}

/**
 * 删除失败邮件
 * @param self
 * @param tiyData
 */
export const deleteFailEmail = (self, tiyData,id) => {
  let param = {
    "id": id,
  };
  self.$apiEmail.deleteFailEmail(param).then(function (response) {
    if(response.success){
      self.$Message.info("删除成功！");
      self.search();
    }else{
      self.$Message.error(response.errorMessage);
    }
    self.$Spin.hide();
  });
}
